﻿using System;
using System.Collections.Generic;
using System.Transactions;
using Bingosoft.Data;
using HHMMS.Core.Model;

namespace HHMMS.Core.Service
{
    public class PurchaseSuppliesPlanService
    {
        private readonly Dao _dao = Dao.Get();

        public PurchaseSuppliesPlan GetPurchaseSuppliesPlan(int docId, string partName, string partModel)
        {
            return this._dao.QueryEntity<PurchaseSuppliesPlan>("PlanManager.PurchaseSuppliesPlan.Get", new { DocId = docId, PartName = partName, PartModel = partModel });                
        }

        public void SaveOrUpdatePurchaseSuppliesPlan(PurchaseSuppliesPlan purchaseSuppliesPlan)
        {
            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required))
            {
                this._dao.ExecuteNonQuery("PlanManager.PurchaseSuppliesPlan.InsertOrUpdate", purchaseSuppliesPlan);
                transactionScope.Complete();
            }
        }

        public void DeletePurchaseSuppliesPlan(int docId, string partName, string partModel)
        {
            using (TransactionScope transactionScope = new TransactionScope())
            {
                this._dao.ExecuteNonQuery("PlanManager.PurchaseSuppliesPlan.Delete", new { DocId = docId, PartName = partName, PartModel = partModel });
                transactionScope.Complete();
            }

        }
        
    }
}